package com.ketangpai.admin.controller;

import com.ketangpai.admin.entity.CourseCatalog;
import com.ketangpai.admin.service.CourseCatalogService;
import com.ketangpai.admin.utils.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/courseCatalog")
@Api(tags = "课程目录")
public class CourseCatalogController {

    @Resource
    private CourseCatalogService courseCatalogService;

    @ApiOperation(value = "课程目录")
    @PostMapping("/chapters")
    public JsonResult<?> getCourseCatalog(@RequestBody Map<String, Integer> params) {
        Integer courseId = params.get("courseId");
        if (courseId== null) {
            return JsonResult.error("courseId不能为空");
        }
        CourseCatalog[] courseCatalog=courseCatalogService.getCourseCatalog(courseId);
        Map<String, Object> result = new HashMap<>();
        result.put("courseCatalog", courseCatalog);
        return JsonResult.success(result);
    }
}
